package com.example.community.dao.elasticsearch;

import com.example.community.entity.DiscussPost;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.elasticsearch.annotations.Highlight;
import org.springframework.data.elasticsearch.annotations.HighlightField;
import org.springframework.data.elasticsearch.annotations.HighlightParameters;
import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface DiscussRepository extends ElasticsearchRepository<DiscussPost, Integer> {

    // 自定义条件查询
    @Highlight(
            fields = {@HighlightField(name = "title"), @HighlightField(name = "content")},
            parameters = @HighlightParameters(preTags = {"<em>"}, postTags = {"</em>"}, numberOfFragments = 0)
    )
    List<SearchHit<DiscussPost>> findByTitleOrContent(String title, String content, Pageable page);
//    Page<SearchHit<DiscussPost>> fuzzySearchWithHighlight(String keyword, Pageable pageable);

}
